package com.usian.admin.lister;

import com.usian.admin.service.WemediaNewsAutoService;
import com.usian.common.constants.message.NewsAutoScanConstants;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author Fay
 * @date 2022/7/12&11:14
 */
@Component
public class WemediaNewsAutoListener {
    @Autowired
    private WemediaNewsAutoService wemediaNewsAutoService;


    @KafkaListener(topics = NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void receiveMsg(ConsumerRecord<?,?> record){
        //判断record是否有值
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            //获取自媒体文章id
            Object value = record.value();
            Integer wmNewId = Integer.parseInt(String.valueOf(value));
            //文章审核
            wemediaNewsAutoService.auditWemediaNews(wmNewId);
        }
    }

}
